*===============================================================================
* Do-file creates "Experimental Dataset: Mobile Salary Treament Effects & Violence Heterogeneity
* Figure 3
*===============================================================================
clear
set more off

cd "~/Dropbox/VFD/REStat_Native_Files/Stata_Files"
local output "~/Dropbox/VFD/REStat_Native_Files/Stata_Files/Output"

use cadg_master_daily_NATIVE.dta, clear

*-------------------------------------------------------------*
*Figure A - Mobile Salary Treatment Effect on M-Paisa Balance *
*-------------------------------------------------------------*
preserve
egen mean_t_c = mean(cumbalance), by(date treat_final)
bys date treat_final: gen numobs = _N
egen sd_t_c = sd(cumbalance), by(date treat_final)
gen se_t_c = sd_t_c/sqrt(numobs)

gen high = mean_t_c+1.96*se_t_c
gen low = mean_t_c-1.96*se_t_c

keep if employeenumber == 1321 | employeenumber == 1340 // selecting one each from treatment and control group
sort employeenumber date
twoway line mean_t_c date if treat_final==0 || line mean_t_c date if treat_final==1 /// 
|| rline high low date, lcolor(edkblue) lpattern(dot) scheme(s2mono) legend(label(1 "Control") label(2 "Treat") label(3 "95 Percent CI")) ///
ytitle("M-Paisa Balance (Afs)") xtitle("Date") ///
xlabel(,labsize(small)) graphregion(fcolor(white))
graph export "`output'/te.png", replace
restore


*-------------------------------------------------------------*
*Figure B - Mobile Salary Treatment Effect on M-Paisa Balance *
*By Baseline Violence Expectations							  *
*-------------------------------------------------------------*

preserve
gen vgroup = 0 if treat_final==0
replace vgroup = 1 if baseline_violence_34==0 & treat_final==1 // below median average violence beliefs
replace vgroup = 2 if baseline_violence_34==1 & treat_final==1 // above median average violence beliefs

egen mean_v = mean(cumbalance), by(vgroup date)
keep if employeenumber == 1321 | employeenumber == 1903 | employeenumber == 1406
twoway line mean_v date if vgroup==0, lpattern(solid) || line mean_v date if vgroup==2, lpattern(longdash) || ///
line mean_v date if vgroup==1, lpattern(shortdash) ///
legend(label(1 "Control") label(3 "Low Violence Treat") label(2 "High Violence Treat")) ///
ytitle("M-Paisa Balance (Afs)") xtitle("Date") scheme(s2mono) ///
xlabel(,labsize(small)) graphregion(fcolor(white))
graph export "`output'/te_bv_baseline.png", replace
restore
